import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';
import 'package:flutter_bmfmap_example/pages/marketpage/componets/gooditemcard.dart';
import 'page/Evaluate.dart';
import 'package:fluttertoast/fluttertoast.dart';

import 'componets/orderslistview.dart';



class OrdarPage extends StatefulWidget {
  const OrdarPage({Key key}) : super(key: key);
  @override
  _OrdarPageState createState() => _OrdarPageState();
}

class _OrdarPageState extends State<OrdarPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // this.getAllOrder();
    // this.getArrearage();
    // this.getSends();
    // this.getGoods();
    // this.getEvaluate();
    // this.getReEvaluate();
  }

  List list = [];
  List list1 = [];
  List list2 = [];
  List list3 = [];
  List list4 = [];
  List list5 = [];

  // 发送请求,获取订单信息
  // getState(url) async {
  //   var dio = new Dio();
  //   dio.options.headers["Authorization"] = this.Authorization;
  //   Response response = await dio.get(url);
  //   print(response.data);
  //   return response.data;
  // }

  // 发送请求删除并更新收藏列表
  removeatindex(int index) async {
    print(index);
    int id = this.list[index]["id"];
    Dio dio = new Dio();

    ///请求地址 获取用户列表
    String url = "/collection/delete";
    //发起get请求
    var response = await Http.get(url, params: {"commodityId": id});
    print(response);
    //更新数据
    setState(() {
      if (response.data) {
        list.removeAt(index);
      }
    });
  }

  getAllOrder() async {
    String url = '/orderForm/getAll';
    var response = await Http.get(url);
    print(response);
    setState(() {
      this.list = response;
    });
  }

  // 1.获取代付款的订单
  getArrearage() async {
    String url = '/orderForm/getState0ByUser';
    var response = await Http.get(url);
    print(response.data);
    setState(() {
      this.list1 = response.data;
    });
  }

  // 2.获取代付款的订单
  getSends() async {
    String url = '/orderForm/getState1ByUser';
    var response = await Http.post(url);
    print(response.data);
    setState(() {
      this.list2 = response.data;
    });
  }

  // 3.获取代付款的订单
  getGoods() async {
    String url = '/orderForm/getState2ByUser';
    Response response = await Http.post(url);
    print(response.data);
    setState(() {
      this.list3 = response.data;
    });
  }

  // 4.获取代付款的订单
  getEvaluate() async {
    String url = '/orderForm/getState3ByUser';
    var response = await Http.post(url);
    print(response.data);
    setState(() {
      this.list4 = response.data;
    });
  }

  // 4.获取代付款的订单
  getReEvaluate() async {
    String url = '/orderForm/getState4ByUser';
    var response = await Http.post(url);
    print(response.data);
    setState(() {
      this.list5 = response.data;
    });
  }

  reGetAllList() {
    this.getAllOrder();
    // this.getArrearage();
    // this.getSends();
    // this.getGoods();
    // this.getEvaluate();
  }

  @override
  Widget build(BuildContext context) {
    // print(list);
    // print(list1);
    // print(list2);
    // print(list3);
    // print(list4);
    return DefaultTabController(
      length: 6,
      child: Scaffold(
        appBar: AppBar(
          title: Text(
            '订单',
            style: TextStyle(color: Colors.black),
          ),
          iconTheme: IconThemeData(color: Colors.black54),
          centerTitle: true,
          backgroundColor: Colors.transparent,
          elevation: 0,
          bottom: TabBar(
            isScrollable: true, //可滚动
            //选中条大小
            indicatorSize: TabBarIndicatorSize.label,
            //选中字体颜色
            labelColor: Color.fromRGBO(123, 122, 123, 1),
            //选项条颜色
            indicatorColor: Color.fromRGBO(193, 194, 196, 1),
            //未选中字体颜色
            unselectedLabelColor: Color.fromRGBO(123, 122, 123, 0.5),

            labelStyle: TextStyle(fontWeight: FontWeight.bold),
            // indicatorColor: Colors.blueGrey, //指示器的颜色
            // labelColor: Colors.blueGrey, //选中文字颜色
            // unselectedLabelColor: Colors.white, //为选中文字颜色
            // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
            tabs: <Widget>[
              Tab(text: "全部"),
              Tab(text: "待付款"),
              Tab(text: "代发货"),
              Tab(text: "待收货"),
              Tab(text: "待评价"),
              Tab(text: "已评价"),
            ],
          ),
          leading: InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border.all(color: Colors.grey[200], width: 0.5),
                    borderRadius: BorderRadius.circular(10),
                    boxShadow: [
                      BoxShadow(
                          color: Colors.black12,
                          blurRadius: 4,
                          spreadRadius: 0,
                          offset: Offset(0, 0))
                    ]),
                child: Icon(
                  Icons.arrow_back,
                  size: 18,
                  color: Colors.blueGrey[800],
                ),
              ),
            ),
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            Container(child: OrdersListview(type: -1,)),
            Container(child: OrdersListview(type: 0,)),
            Container(child: OrdersListview(type: 1,)),
            Container(child: OrdersListview(type: 2,)),
            Container(child: OrdersListview(type: 3,)),
            Container(child: OrdersListview(type: 4,)),
          ],
        ),
      ),
    );
  }
}

